'use strict';

const Service = require('egg').Service;

class LinkService extends Service {
    async find(key1,key2) {
        let sql = `SELECT * FROM synopsis_link WHERE name Like "%${key1}%" AND  nameOther Like "%${key2}%"`;
        const data = await this.app.mysql.query(sql);
        return {data};
      }
    
      async findto(key) {
        let data = new Array();
        let sql = `SELECT * FROM synopsis_link WHERE name Like "%${key}%"`;
        data = await this.app.mysql.query(sql);
        return { data };
      }
    
      async save (key1,key2){
          let sql = `INSERT INTO synopsis_link (name,nameOther,row) VALUES ("${key1}", "${key2}",0)`;
          await this.app.mysql.query(sql);
      }

      async saveData (key1,key2,row){
        let sql = `INSERT INTO synopsis_link (name,nameOther,row) VALUES ("${key1}", "${key2}","${row}")`;
        await this.app.mysql.query(sql);
    }
    
      async update(key1,key2,log){
        let sql = `UPDATE synopsis_link SET row="${log}" WHERE name="${key1}" AND nameOther="${key2}"`;
          await this.app.mysql.query(sql);
      }
}

module.exports = LinkService;
